using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using T2.WebSecurity.ASPMVC.Entity.Interface;
using T2.WebSecurity.ASPMVC.Entity;
using T2.WebSecurity.Business.Entities;
using T2.WebSecurity.Business.Entities.Interfaces;
using T2.WebSecurity.ASPMVC.Entity.Search;
using T2.WebSecurity.ASPMVC.Entity.Search.Interface;
using T2.WebSecurity.Business.Entities.Search;
using T2.WebSecurity.Business.Entities.Search.Interfaces;
using T2.WebSecurity.ASPMVC.Entity.Translators;
using T2.WebSecurity.ASPMVC.Entity.Translators.Search;


namespace T2.WebSecurity.ASPMVC.ViewModel
{

	public class ApplicationProfileDataViewModel
	{
		Business.BusinessService bs = new Business.BusinessService();
		public ApplicationProfileDataViewModel(bool loadParent)
		{
		if (loadParent)
			{
				this.LoadApplicationList();
			}
		}
		
		private String m_header;
		public String Header
        {
            get
            {
                return "Application Profile Data";
            }
			
			set
            {
                m_header = value;
            }
        }
		
		private String m_title;
		public String Title
        {
            get
            {
                return "Application Profile Data";
            }
			
			set
            {
                m_title = value;
            }
        }
		
		private IApplicationProfileData_ui m_model;
		public IApplicationProfileData_ui Model
		{
			get
			{
				return m_model;
			}
			set
			{
				m_model = value;
			}
		}
		private List<IApplication_ui> m_applicationlist;
		public List<IApplication_ui> Application_List
		{
			get
			{
				return m_applicationlist;
			}
			set
			{
				m_applicationlist = value;
			}
		}

		 private void LoadApplicationList()
		{
			IApplication_biz param = new Application_biz();
			param.Action = "GetAll";
			param.PageNumber = 1;
			param.PageSize = 20;
			param.SortColumn = "ApplicationID";
			param.SortType = "desc";
			param.TotalRows = -1;
			List<IApplication_biz> retVal = bs.ApplicationController_Get(param, true, true);
			List<IApplication_ui> LoadRetVal = new List<IApplication_ui>();
			ApplicationUITranslator trans = new ApplicationUITranslator();
			foreach (IApplication_biz item in retVal)
			{
				IApplication_ui temp = new Application_ui();
				temp = trans.TranslateFromBusinessLayer(item);
				LoadRetVal.Add(temp);
			}
			m_applicationlist = LoadRetVal;
		}


        
		
		public void LoadModel(IApplicationProfileData_ui param)
        {
            ApplicationProfileDataUITranslator trans = new ApplicationProfileDataUITranslator();
            IApplicationProfileData_biz bizParam = trans.TranslateToBusinessLayer(param);
            List<IApplicationProfileData_biz> tempRetVal = bs.ApplicationProfileDataController_Get(bizParam, true, true);
            IApplicationProfileData_ui retVal = new ApplicationProfileData_ui();
            if (tempRetVal != null && tempRetVal.Count > 0)
            {
                retVal = trans.TranslateFromBusinessLayer(tempRetVal.First());
            }

            m_model = retVal;

        }

        public Int32 Set(IApplicationProfileData_ui param)
        {
            ApplicationProfileDataUITranslator trans = new ApplicationProfileDataUITranslator();
            IApplicationProfileData_biz bizParam = trans.TranslateToBusinessLayer(param);
            IDictionary<string,int> r = bs.ApplicationProfileDataController_Set(bizParam);
            var ret = r.ToList().Select(s => new { Key = s.Key, Value = s.Value });
            Int32 retVal = ret.Where(z => z.Key == "Return_Value").Select(m => m.Value).FirstOrDefault();
			return retVal;
        }

       

        public List<IApplicationProfileData_ui> SearchList(IApplicationProfileDataSearch_ui param)
        {
            ApplicationProfileDataUISearchTranslator transSearch = new ApplicationProfileDataUISearchTranslator();
            IApplicationProfileDataSearch_biz bizParam = transSearch.TranslateToBusinessLayer(param);
            List<IApplicationProfileData_biz> retValBiz = bs.ApplicationProfileDataController_Search(bizParam, true, true);
            List<IApplicationProfileData_ui> retVal = new List<IApplicationProfileData_ui>();
            ApplicationProfileDataUITranslator trans = new ApplicationProfileDataUITranslator();
            foreach (IApplicationProfileData_biz item in retValBiz)
            {
                IApplicationProfileData_ui temp = trans.TranslateFromBusinessLayer(item);
                retVal.Add(temp);
            }

            
            return retVal;

        }

        

        public List<IApplicationProfileData_ui> ModelList(IApplicationProfileData_ui param)
        {

            ApplicationProfileDataUITranslator trans = new ApplicationProfileDataUITranslator();
            IApplicationProfileData_biz bizParam = trans.TranslateToBusinessLayer(param);
            List<IApplicationProfileData_biz> retValBiz = bs.ApplicationProfileDataController_Get(bizParam, true, true);
            List<IApplicationProfileData_ui> retVal = new List<IApplicationProfileData_ui>();
            foreach (IApplicationProfileData_biz item in retValBiz)
            {
                IApplicationProfileData_ui temp = trans.TranslateFromBusinessLayer(item);
                retVal.Add(temp);
            }

            
            return retVal;

        }
		
	}
}
